package com.soft.javase.day11.copy;

import java.io.*;

/**
 * @author yzh
 * @desc TODO
 * @date 2025/5/9
 */
public class FileCopy {

    public static void main(String[] args) {
        copyFile("source.txt", "target.txt");
    }

    public static void copyFile(String sourcePath, String targetPath) {
        try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(sourcePath));
             BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(targetPath))) {

            byte[] buffer = new byte[8192];
            int len;
            while ((len = bis.read(buffer)) != -1) {
                bos.write(buffer, 0, len);
            }
            System.out.println("文件拷贝完成");

        } catch (IOException e) {
            System.err.println("文件拷贝失败");
            e.printStackTrace();
        }
    }
}
